// Copyright (C) 2025, ZWSOFT Co., LTD.(Guangzhou)
// Licensed under the MIT License. See LICENSE in the project root for license information.

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using TestClient.Domain;

namespace TestClient.ViewModel;
public partial class MultipleDeletionTestViewModel : PageViewModelBase
{
    [ObservableProperty]
    private string selectedCurves = string.Empty;
    private List<string> curves = [];
    [ObservableProperty]
    private string selectedSurfaces = string.Empty;
    private List<string> surfaces = [];

    public IAsyncRelayCommand SelectCurvesCommand { get; }
    public IAsyncRelayCommand SelectSurfacesCommand { get; }
    public IAsyncRelayCommand DeleteCurvesCommand { get; }
    public IAsyncRelayCommand DeleteSurfacesCommand { get; }

    public MultipleDeletionTestViewModel(VFAdapterWrapper wrapper, ISnackNotifyService notifyService) : base(wrapper, notifyService)
    {
        SelectCurvesCommand = CreateAsyncRpcCommand(SelectCurves);
        SelectSurfacesCommand = CreateAsyncRpcCommand(SelectSurfaces);
        DeleteCurvesCommand = CreateAsyncRpcCommand(DeleteCurves);
        DeleteSurfacesCommand = CreateAsyncRpcCommand(DeleteSurfaces);
    }

    private async Task SelectCurves()
    {
        EnsureConnected();
        curves = await Task.Run(() =>
        {
            return Wrapper.MultiSelect("Curve");
        });
        SelectedCurves = string.Join(", ", curves);
    }

    private async Task SelectSurfaces()
    {
        EnsureConnected();
        surfaces = await Task.Run(() =>
        {
            return Wrapper.MultiSelect("Surface");
        });
        SelectedSurfaces = string.Join(", ", surfaces);
    }

    private async Task DeleteCurves()
    {
        EnsureConnected();
        await Task.Run(() =>
        {
            Wrapper.DeleteCurves([.. curves]);
        });
    }

    private async Task DeleteSurfaces()
    {
        EnsureConnected();
        await Task.Run(() =>
        {
            Wrapper.DeleteSurfaces([.. surfaces]);
        });
    }

}
